package com.oa.ylms.apps.business.news.impl;

import java.util.List;

import com.oa.ylms.apps.business.news.INewsCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.news.INewsCategoryDao;
import com.oa.ylms.apps.entity.news.NewsCategoryValue;

public class NewsCategoryServiceImpl implements INewsCategoryService {
	private INewsCategoryDao categoryDao;
	private NewsCategoryValue newsCategory;

	// Service method
	@Override
	public int addNewsCategory(String categoryName, int states) throws Exception {
		newsCategory.setCategoryName(categoryName);
		newsCategory.setStates(states);
		return categoryDao.addNewsCategory(newsCategory);
	}


	@Override
	public boolean deleteNewsCategory(int categoryId) throws Exception {
		newsCategory=queryCategoryById(categoryId);
		newsCategory.setStates(IDEDStates.DELETE);
		return categoryDao.editNewsCategory(newsCategory);
	}
	@Override
	public boolean modifyNewsCategory(int categoryId, String categoryName,
			int states) throws Exception {
		newsCategory = queryCategoryById(categoryId);
		newsCategory.setCategoryName(categoryName);
		newsCategory.setStates(states);
		return categoryDao.editNewsCategory(newsCategory);
	}
	@Override
	public List<NewsCategoryValue> queryAllCategory() throws Exception {
		return categoryDao.queryCategoryByStates(newsCategory);
	}
	@Override
	public List<NewsCategoryValue> queryCategoryByStates(Integer states) throws Exception {
		newsCategory.setStates(states);
		return categoryDao.queryCategoryByStates(newsCategory);
	}
	@Override
	public NewsCategoryValue queryCategoryById(int categoryId) throws Exception {
		newsCategory.setCategoryId(categoryId);
		return categoryDao.queryCategoryById(newsCategory);
	}
	@Override
	public boolean toDisable(int categoryId) throws Exception {
		newsCategory = queryCategoryById(categoryId);
		newsCategory.setStates(IDEDStates.DISABLE);
		return categoryDao.editNewsCategory(newsCategory);
	}
	@Override
	public boolean toEnable(int categoryId) throws Exception {
		newsCategory = queryCategoryById(categoryId);
		newsCategory.setStates(IDEDStates.ENABLE);
		return categoryDao.editNewsCategory(newsCategory);
	}

	// Service property accessors

	public INewsCategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(INewsCategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public NewsCategoryValue getNewsCategory() {
		return newsCategory;
	}

	public void setNewsCategory(NewsCategoryValue newsCategory) {
		this.newsCategory = newsCategory;
	}



}
